package cn.stylefeng.guns.sys.modular.tao.service.serviceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.tao.entity.Goods;
import cn.stylefeng.guns.sys.modular.tao.entity.PictureVideo;
import cn.stylefeng.guns.sys.modular.tao.mapper.PictureVideoMapper;
import cn.stylefeng.guns.sys.modular.tao.model.params.PictureVideoParam;
import cn.stylefeng.guns.sys.modular.tao.model.result.PictureVideoResult;
import cn.stylefeng.guns.sys.modular.tao.service.PictureVideoService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 * 视频图文表
 *
 * @author 石博士
 * @since 2019-11-06
 */
@Service
public class PictureVideoServiceImpl extends ServiceImpl<PictureVideoMapper, PictureVideo> implements PictureVideoService {


    @Autowired
    private PictureVideoMapper pictureVideoMapper;


    @Override
    public void add(PictureVideoParam param){
        PictureVideo entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PictureVideoParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PictureVideoParam param){
        PictureVideo oldEntity = getOldEntity(param);
        PictureVideo newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PictureVideoResult findBySpec(PictureVideoParam param){
        return null;
    }

    @Override
    public List<PictureVideoResult> findListBySpec(PictureVideoParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(PictureVideoParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }



    private Serializable getKey(PictureVideoParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PictureVideo getOldEntity(PictureVideoParam param) {
        return this.getById(getKey(param));
    }

    private PictureVideo getEntity(PictureVideoParam param) {
        PictureVideo entity = new PictureVideo();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }





    /**
     * 查询id最大值
     */
    @Override
    public String pictureVideoMax() {
        return pictureVideoMapper.pictureVideoMax();
    }



    /**
     * 修改图片接口
     */
    public void updateImg(PictureVideo pictureVideo){
        pictureVideoMapper.updateImg(pictureVideo);
    }




}
